/**
 * 判断值类型
 *
 * @export
 * @param {*} obj 需要判断的类型
 * @param {*} type 可选值，直接与某个类型进行判断
 * @return {*}
 */
export default function (obj, type) {
    var objectString = Object.prototype.toString.call(obj);
    if (type) {
        var result = null;
        switch (type) {
            case "string":
                result = objectString == "[object String]";
                break;
            case "async":
                result = objectString == "[object AsyncFunction]";
                break;
            case "function":
                result = objectString == "[object Function]";
                break;
            case "array":
                result = objectString == "[object Array]";
                break;
            case "number":
                result = objectString == "[object Number]" && obj === obj;
                break;
            case "date":
                result = objectString == "[object Date]";
                break;
            case "object":
                result = objectString == "[object Object]";
                break;
            case "bool":
                result = objectString == "[object Boolean]";
                break;
            case "regExp":
                result = objectString == "[object RegExp]";
                break;
            case "null":
                result = objectString == "[object Null]";
                break;
            case "undefined":
                result = objectString == "[object Undefined]";
                break;
            case "promise":
                result = objectString == "[object Promise]";
                break;
            case "NaN":
                result = isNaN(obj);
                break;
        }
        return result;
    } else {
        var mold = null;
        switch (objectString) {
            case "[object String]":
                mold = "string";
                break;
            case "[object AsyncFunction]":
                mold = "async";
                break;
            case "[object Function]":
                mold = "function";
                break;
            case "[object Array]":
                mold = "array";
                break;
            case "[object Number]":
                if (obj !== obj) {
                    mold = "NaN";
                } else {
                    mold = "number";
                }
                break;
            case "[object Date]":
                mold = "date";
                break;
            case "[object Object]":
                mold = "object";
                break;
            case "[object Boolean]":
                mold = "bool";
                break;
            case "[object RegExp]":
                mold = "regExp";
                break;
            case "[object Null]":
                mold = "null";
                break;
            case "[object Promise]":
                mold = "promise";
                break;
            case "[object Undefined]":
                mold = "undefined";
                break;
        }
        return mold;
    }
}
